package cz.muni.fi.pb162.project.geometry;


/**
 * Creates a simple (irregular) polygon.
 * 
 * @author Martin Pasko
 * @version 05_11_2012
 */
public class ArrayPolygon extends SimplePolygon
{
    private Vertex2D[] vertex = null;
    
    /**
     *  Creates a simple (irregular) polygon.
     *  @param vertex array of Vertex2D vertices
     */
    
    public ArrayPolygon(Vertex2D[] vertex) {
        
        if(vertex == null) {
            throw new IllegalArgumentException("Pole nebolo inicializovane");
        }
        
        for(int i=0; i<vertex.length; i++) {
            
            if(vertex[i] == null) {
                throw new IllegalArgumentException("Element c. "+i+"nebol inicializovany.");
            }
        }
        
        this.vertex = new Vertex2D[vertex.length];                      
        System.arraycopy(vertex, 0, this.vertex, 0, vertex.length);
    }
    

    public Vertex2D getVertex(int index) {
        
        if(index < 0) {
            throw new IllegalArgumentException("Index musi byt nezaporne cislo");
        }
        
        return vertex[index%getNumVertices()];
    }

    public int getNumVertices() {
    
        return vertex.length;
    }
}
